var PATH_PREFIX ="";

function setPathPrefix(path){
	PATH_PREFIX =  path;
}

$(function(){
	WASP_WIDGET.initializeSelectStyle();
	WASP_WIDGET.registerResetClearEvent();
	WASP_WIDGET.triggerDateStyleWithYMD("#beginDate2");
	WASP_WIDGET.triggerDateStyleWithYMD("#endDate2");
    WASP_WIDGET.triggerCustInfoSelect("custNo2");
	WASP_WIDGET.triggerPrdInfoSelect("productId2");
});

var $custPortionChkReportList = $('#custPortionChkReportList');

$(function() {
	$custPortionChkReportList.jqGrid({   
		url:PATH_PREFIX + 'custPortionListPage.do', 
		/*caption:'客户份额对账列表<button type="button" class="btn btn-default btn-sm btn-small btn-fullscreen" title="" tabindex="-1"><i class="fa fa-arrows-alt icon-fullscreen"></i></button>',*/  
		datatype: "json",
		colNames:["id", "客户名称","产品名称","日期","份额","冻结份额","可用份额","市值","成本","浮动盈亏"],        
		colModel:[  { name: 'portionCheckId', index: 'portionCheckId', key: true, hidden:true },       
		            { name: 'custName', index: 'custName', width: 30, resizable: true, sortable: false },
		            { name: 'productName', index: 'productName', width: 30, resizable: true, sortable: false },
		            { name: 'checkDate', index: 'checkDate', width: 30, resizable: true, sortable: false },
		            { name: 'portion', index: 'portion', width: 30, resizable: true, sortable: false },
		            { name: 'frozenPortion', index: 'frozenPortion', width: 30, resizable: true, sortable: false },
		            { name: 'availablePortion', index: 'availablePortion', width: 30, resizable: true, sortable: false },
		            { name: 'marketValue', index: 'marketValue', width: 30, resizable: true, sortable: false },
		            { name: 'degression', index: 'degression', width: 30, resizable: true, sortable: false },
		            { name: 'floatProfitLoss', index: 'floatProfitLoss', width: 30, resizable: true, sortable: false }
				  ],
		rowNum: 20,
        rowList: [20, 30, 50],
        rownumbers: true,
        rownumWidth: 50,
        postData: {},
        prmNames: { search: "search", page: "pageNo", rows: "limit" },
        height: 'auto',
        width: false,
        autowidth:true,
        editurl: '',
        viewrecords: true,
        cellEdit: false,
        shrinkToFit: true,
        grouping: false,
        jsonReader: {
            root: "items", //结果集
            records: "total", //总记录数 
            total: "pageCount", //总页数
            page: "pageNo", //当前页 
            repeatitems: false // (4) 
        },  
		multiselect:false,
		pager: "#custPortionChkReportListPage",						
		viewrecords: true,
		hidegrid: false, 
		gridComplete: function(){
			var ids = $custPortionChkReportList.jqGrid('getDataIDs');
			for(var i = 0;i < ids.length;i++){
				var rowId = ids[i];
				$custPortionChkReportList.jqGrid('setRowData', ids[i]);
			}	
		}
	});
	$custPortionChkReportList.navGrid('#custPortionChkReportListPage',{edit:false,add:false,del:false,search:false,refreshstate:'current'});
	$custPortionChkReportList.jqGrid('setFrozenColumns');
	jqGridResize($custPortionChkReportList);
});

//绑定回车事件,查询
$("body").keypress(function(event){
	var key = event.which;
	if(key == "13"){
		queryByCondtion(true);
	}
});

function queryByCondtion2(flag) {
	var beginDate2 = $.trim($("#beginDate2").val());   
	var endDate2   = $.trim($("#endDate2").val());   
	var custNo2    = $.trim($("#custNo2").val()); 
	var productId2 = $.trim($("#productId2").val()); 
	var postData = $custPortionChkReportList.jqGrid("getGridParam", "postData");
    $.extend(postData, {
        'sp[beginDate]':beginDate2,
        'sp[endDate]':endDate2,
        'sp[productId]':productId2,
        'sp[custNo]':custNo2
    });
    if (flag) {
    	$custPortionChkReportList.jqGrid("setGridParam",{"datatype": "json"}).trigger("reloadGrid", [{ page: 1 }]); //重新载入Grid表格
    } else {
    	$custPortionChkReportList.jqGrid("setGridParam",{"datatype": "json"}).trigger("reloadGrid"); //重新载入Grid表格
    }
}


